<template>
  <SearchList :columns="columns" :pagination="pagination" ref="refList"
               :load-data="loadData" :title="'审计日志'" :search-form="searchItems" />
</template>

<script setup lang="ts" name="auditLog">

import {ref} from "vue";
import {loadAuditLogPage} from "@/apis";
import SearchList from "@/widget/list/SearchList.vue";
import {useStore} from "@/stores";
import {userDataWatch} from "@/utils/UseDataWatch";

const store = useStore();

const loadData = async (params: any) => {
  if ('全部' == params.actionType) {
    params.actionType = '';
  }

  const plat: any = store.getCurrentPlatform();
  const result = await loadAuditLogPage({
    platformId: plat.id,
    ...params
  });

  return result;
}

const {refList} = userDataWatch(false);

const pagination = ref<Pagination>({
  current: 1,
  pageSize: 20,
  total: 0,
});

const searchItems = ref([
  {
    type: 'select',
    name: 'actionType',
    label: '操作类型',
    size: 'default',
    placeholder: '',
    clearable: true,
    defValue: '全部',
    width: '160px',
    options: [
      {
        label: '全部',
        value: '全部',
      },
      {
        label: 'add',
        value: 'add',
      },
      {
        label: 'delete',
        value: 'delete',
      },
      {
        label: 'save',
        value: 'save',
      },
    ]
  },
  {
    type: 'input',
    name: 'userName',
    label: '用户名称',
    size: 'default',
    placeholder: '请输入用户名称',
    clearable: true,
    defValue: '',
  },
  {
    type: 'input',
    name: 'clientId',
    label: '客户标识',
    size: 'default',
    placeholder: '请输入客户标识',
    clearable: true,
    defValue: '',
  },
]);

const columns = ref([
  {
    id: 'id',
    name: '标识',
    hideCol: true,
    show: false,
  },
  {
    id: 'clientId',
    name: '客户标识',
    show: true,
  },
  {
    id: 'userName',
    name: '用户名称',
    show: true,
  },
  {
    id: 'actionType',
    name: '操作类型',
    show: true,
  },
  {
    id: 'actionStatus',
    name: '操作状态',
    show: true,
  },
  {
    id: 'actionTime',
    name: '操作时间',
    show: true,
  },
  {
    id: 'actionData',
    name: '操作数据',
    show: true,
  },
  {
    id: 'failInfo',
    name: '失败信息',
    show: true,
  },
]);

</script>

<style scoped>
.el-form-item-class .el-form-item__label {
  font-size: 12px;
}

</style>
